package org.yxj.changethemeapp.v

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import org.yxj.changethemeapp.LogUtils

/**
 * 事件分发测试
 *
 * @author  on 2024/6/25
 */
class OnTouchView : FrameLayout {

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
    constructor(context: Context, attributeSet: AttributeSet?, defStyleRes: Int) : super(
        context,
        attributeSet,
        defStyleRes
    )


    /**
     * 分发
     */
    override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
        LogUtils.LOG_V("[OnTouchViewA]->dispatchTouchEvent")
//        event?.let {
//            when(it.action){
//                MotionEvent.ACTION_DOWN ->{ LogUtils.LOG_V("[OnTouchViewA]->dispatchTouchEvent is ACTION_DOWN") }
//                MotionEvent.ACTION_MOVE ->{LogUtils.LOG_V("[OnTouchViewA]->dispatchTouchEvent is ACTION_MOVE")}
//                MotionEvent.ACTION_UP ->{LogUtils.LOG_V("[OnTouchViewA]->dispatchTouchEvent is ACTION_UP")}
//            }
//        }
        return super.dispatchTouchEvent(event)
    }


    /**
     * 拦截
     */
    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        LogUtils.LOG_V("[OnTouchViewA]->onInterceptTouchEvent")
//        ev?.let {
//            when (it.action) {
//                MotionEvent.ACTION_DOWN -> {
//                    LogUtils.LOG_V("[OnTouchViewA]->onInterceptTouchEvent is ACTION_DOWN")
//                }
//
//                MotionEvent.ACTION_MOVE -> {
//                    LogUtils.LOG_V("[OnTouchViewA]->onInterceptTouchEvent is ACTION_MOVE")
//                }
//
//                MotionEvent.ACTION_UP -> {
//                    LogUtils.LOG_V("[OnTouchViewA]->onInterceptTouchEvent is ACTION_UP")
//                }
//            }
//        }
        return super.onInterceptTouchEvent(ev)
    }


    /**
     * 执行
     */
    override fun onTouchEvent(event: MotionEvent?): Boolean {
        LogUtils.LOG_V("[OnTouchViewA]->onTouchEvent")
//        event?.let {
//            when(it.action){
//                MotionEvent.ACTION_DOWN ->{ LogUtils.LOG_V("[OnTouchViewA]->onTouchEvent is ACTION_DOWN") }
//                MotionEvent.ACTION_MOVE ->{LogUtils.LOG_V("[OnTouchViewA]->onTouchEvent is ACTION_MOVE")}
//                MotionEvent.ACTION_UP ->{LogUtils.LOG_V("[OnTouchViewA]->onTouchEvent is ACTION_UP")}
//            }
//        }
        return super.onTouchEvent(event)
    }
}